<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>视频管理</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="viewCourse">
    <template class="data">
        <el-input
                style="width:30%;margin-bottom: 10px;color: blue"
                placeholder="请输入搜索内容"
                v-model="query"
                clearable>
        </el-input>
        <el-button type="primary" size="small" @click="search()" style="height: 40px;width: 80px;margin-bottom: 10px">搜索</el-button>
        <el-table
                :data="tableData"
                border
                style="width: 96%">
            <el-table-column
                    prop="videoId"
                    label="视频ID"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="videoName"
                    label="视频名"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="videoDesc"
                    label="视频描述"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="videoSecond"
                    label="视频时长"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="videoCounts"
                    label="视频点击量"
                    width="140">
            </el-table-column>
            <el-table-column
                    prop="videoPath"
                    label="点击查看视频内容"
                    width="300">
                <video src="scope.row.videoPath0" controls autoplay></video>
            </el-table-column>
            <el-table-column label="操作" width="170" >
                <template slot-scope="scope">
                    <div id="update">
                        <el-popover
                                placement="right"
                                width="900"
                                height="600"
                                trigger="click">
                            <el-button  @click="getUpdateVideo(scope.row.videoId)" slot="reference">更新</el-button>
                            <el-descriptions v-model="form" title="学生信息更新" :column="3"  border>
                                <template slot="extra">
                                    <el-button type="primary" size="small" @click="submit">提交</el-button>
                                    <el-button type="primary" size="small" @click="reset">重置</el-button>
                                </template>
                                <el-descriptions-item>
                                    <template slot="label">
                                        视频ID
                                    </template>
                                    <el-input v-model="form.videoId" style="width: 200px;height: 30px"></el-input>
                                </el-descriptions-item>
                                <el-descriptions-item>
                                    <template slot="label">
                                        视频名
                                    </template>
                                    <el-input v-model="form.videoName" style="width: 200px;height: 30px" ></el-input>
                                </el-descriptions-item>
                                <el-descriptions-item>
                                    <template slot="label">
                                        视频描述
                                    </template>
                                    <el-input v-model="form.videoDesc" style="width: 200px;height: 30px"></el-input>
                                </el-descriptions-item>
                                <el-descriptions-item>
                                    <template slot="label">
                                        视频时长
                                    </template>
                                    <el-input v-model="form.videoSecond" style="width: 200px;height: 30px"></el-input>
                                </el-descriptions-item>
                                <el-descriptions-item>
                                    <template slot="label">
                                        视频点击量
                                    </template>
                                    <el-input v-model="form.videoCounts" style="width: 200px;height: 30px"></el-input>
                                </el-descriptions-item>
                                <el-descriptions-item>
                                    <template slot="label">
                                        点击查看视频内容
                                    </template>
                                    <el-input v-model="form.videoPath" style="width: 200px;height: 30px" ></el-input>
                                </el-descriptions-item>
                            </el-descriptions>
                        </el-popover>
                    </div>
                    <el-button  @click="deleteVideo(scope.row.videoId)" >删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination
                :current-page="current"
                :page-size="limit"
                :total="total"
                style="padding:30px 0; margin-top:20px; text-align: center;"
                layout="prev, pager, next"
                @current-change="getVideoList"></el-pagination>
    </template>
</div>

<script src="../../js/vue.js"></script>
<script src="../../js/axios.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>

    new Vue({
        el:'#viewCourse',
        data : function (){
            return{
                tableData: [],  //表格中的所有数据
                current:0,      //当前页码
                limit:3,        //每页展示记录数
                total:0,        //总记录数
                query:'',        //查询条件
                form:{
                    videoId:'',
                    videoName:'',
                    videoDesc:'',
                    videoSecond:'',
                    videoCounts:'',
                    videoPath:'',
                }
            }
        },
        created(){
            this.getVideoList()
        },
        methods: {
            search(){
                this.getVideoList()
            },
            getVideoList(page=1){
                this.current = page
                axios.get('/viewVideo?current='+this.current+'&query='+this.query)
                    .then(response=>{
                        console.log(response)
                        this.tableData = response.data.data.pageInfo.list
                        this.current = response.data.data.pageInfo.pageNum
                        this.total = response.data.data.pageInfo.total
                        this.query = response.data.data.query
                    })
                    .catch(error=>{
                        console.log(error)
                    })
            },
            reset(){
                videoId=null
                videoName=null
                videoDesc=null
                videoSecond=null
                videoCounts=null
                videoPath=null
            },
            deleteVideo(videoId){
                console.log(videoId)
                axios.delete('/deleteVideo/${videoId}?videoId=' + videoId)
                    .then(response=>{
                        let code = response.data.code
                        let msg = response.data.msg
                        if(code==200){
                            this.$message({showClose: true,message: msg,type: 'success'});
                            //跳转查询用户列表组件
                            this.getUserList()
                        }else{
                            this.$message({showClose: true,message: msg,type: 'error'});
                        }
                    })
            },
            getUpdateVideo(videoId){
                console.log(videoId)
                axios.get(`/getUpdateVideo/${videoId}`)
                    .then(response=>{
                        let code = response.data.code
                        let message = response.data.message
                        if (code == 200){
                            this.form = response.data.data
                        }else {
                            this.$message({showClose:true,message:message,type:'error'})
                        }
                    })
            },
            submit(){
                console.log(this.form)
                // let user = this.form
                axios.put('/updateVideo',this.form)
                    .then(response=>{
                        let code = response.data.code
                        console.log(code)
                        let message = response.data.message
                        if (code == 200){
                            this.$message({showClose:true,message:message,type:'success'})
                            this.getVideoList()
                        }else {
                            this.$message({showClose:true,message:message,type:'error'})
                        }
                    })
                    .catch(error => {
                        console.log(error)
                    })
            },

        }
    })
</script>

</body>
</html>